Interactive Graph example
ggplotly(
time_series_long_joined %>%
group_by(Country_Region,Date) %>%
summarise_at(c("Confirmed", "Deaths"), sum) %>%
filter (Country_Region == "US") %>%
ggplot(aes(x = Date, y = Deaths)) +
geom_point() +
geom_line() +
ggtitle("US COVID-19 Deaths")
)
Animated Graph example
library(gganimate)
library(transformr)
library(gifski)
theme_set(theme_bw())
data_time <- time_series_long_joined %>%
group_by(Country_Region,Date) %>%
summarise_at(c("Confirmed", "Deaths"), sum) %>%
filter (Country_Region %in% c("China","Korea, South","Japan","Italy","US"))
p <- ggplot(data_time, aes(x = Date, y = Confirmed, color = Country_Region)) +
geom_point() +
geom_line() +
ggtitle("Confirmed COVID-19 Cases") +
geom_point(aes(group = seq_along(Date))) +
transition_reveal(Date)
# Some people needed to use this line instead
# animate(p,renderer = gifski_renderer(), end_pause = 15)
animate(p, end_pause = 15)

#
Challenge 2
Turn one of the exercises from Lab 5 into an interactive graph with plotyly
time_series_long_joined_ratio <- time_series_long_joined %>%
group_by(Country_Region, Date) %>%
summarise(Total_Confirmed = sum(Confirmed), Total_Deaths = sum(Deaths)) %>%
mutate(Ratio = Total_Deaths / Total_Confirmed)
time_series_long_total_deaths <- time_series_long_joined_ratio %>%
group_by(Country_Region) %>%
summarise(Deaths = sum(Total_Deaths)) %>%
arrange(desc(Deaths)) %>%
slice(1:10)
g <- time_series_long_joined_ratio %>%
filter(Country_Region %in% c("US", "Brazil", "United Kingdom", "Italy", "Mexico", "France", "Spain", "India", "Iran", "Peru")) %>%
ggplot(aes(x = Date, y = Total_Deaths, fill = Country_Region, color = Country_Region)) +
geom_point() +
geom_line() +
ggtitle("The Top 10 Countries by Total Deaths") +
transition_reveal(Date)
animate(g,renderer = gifski_renderer(), end_pause = 15)

Challenge 3
Create an animated graph of your choosing using the time series data to display an aspect (e.g. states or countries) of the data that is important to you.
#Data Wrangling
download.file(url="https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_US.csv", destfile = "data/time_series_covid19_confirmed_US.csv")
time_series_covid19_confirmed_US <- read.csv("data/time_series_covid19_confirmed_US.csv")
time_series_covid19_confirmed_US_totals <- time_series_covid19_confirmed_US %>% select(-c(UID,iso2,iso3,code3,FIPS,Lat,Long_,Combined_Key,Admin2,Country_Region)) %>% group_by(Province_State) %>% summarise_each(funs(sum))
time_series_covid19_confirmed_US_totals <- time_series_covid19_confirmed_US_totals %>% rename_at(vars(starts_with("X")), funs(str_remove(., "X")))
confirmed_US_totals_long <- time_series_covid19_confirmed_US_totals %>% pivot_longer(-c(Province_State), names_to = "Date", values_to = "Confirmed")
confirmed_US_totals_long$Date <- as.Date(confirmed_US_totals_long$Date, format = "%m.%d.%y")
ten_highest_confirmed_df <- confirmed_US_totals_long %>%
group_by(Province_State) %>%
summarise("Confirmed_Total"= sum(Confirmed)) %>%
arrange(desc(Confirmed_Total)) %>%
head(10)
#Graph!
c <- confirmed_US_totals_long %>%
filter(Province_State %in% ten_highest_confirmed_df$Province_State) %>%
ggplot(aes(x = Date, y = Confirmed)) +
geom_point() +
geom_line() +
ggtitle("Top 10 US States by Total Confirmed Cases") +
facet_wrap(~Province_State) +
transition_reveal(Date)
animate(c, end_pause = 15)
